const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports = {
  entry: './src/index.ts',
  module: {
    rules: [{
      test: /\.tsx?$/,
      use: 'ts-loader',
      exclude: /node_modules/
    }, {
      test: /\.css?$/,
      use: ['style-loader', 'css-loader'],
    }]
  },
  resolve: {
    extensions: ['.ts', '.js']
  },
  devServer: {
    contentBase: path.join(__dirname, 'dist'),
    hot: true,
    port: 9000,
    proxy: {
      '/files': {
        target: 'http://localhost:8080/files',
        pathRewrite: { '^/files': '' },
      }
    }
  },
  optimization: {
    splitChunks: {
      chunks: 'all',
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: '显示器测试',
    }),
    new webpack.ProvidePlugin({
      PIXI: 'pixi.js',
    }),
  ],
  externalsType: 'script',
  externals: {
    "pixi.js": ['https://cdn.bootcdn.net/ajax/libs/pixi.js/5.3.3/pixi.min.js', 'PIXI']
  },
  devtool: 'source-map',
  mode: 'development',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js',
  }
};
